package kr.ac.konkuk.dblab.point.quadtree;

public abstract class Visitor {
	private Root root;
	
	public Visitor(Root root) {
		this.root = root;
	}
	
	public void visit() {
		visit(root);
	}
	
	private int visit(Node node) {
		if (node == null) {
			return 0;
		}
		
		if (doIt(node)) {
			return -1;
		}
		
		if (node instanceof CompositeNode) {
			CompositeNode cnode = (CompositeNode)node;
			for (int i = 0 ; i < CompositeNode.CHILD_COUNT ; ++i) {
				node = cnode.child(i);
				if (visit(node) < 0) {
					return -1;
				}
			}
		}
		
		return 1;
	}
	
	public abstract boolean doIt(Node node);
}
